#ifndef __MPOOL_H__
#define __MPOOL_H__

#define MP_OVERHEAD 8

typedef struct MPool_t MPool;

/*  Create the memory pool. The min blockSize is 2 bytes(sof(short)), and the max number of blocks is 65535 (USHRT_MAX) *
*   Supply the memory by the 3rd param. The operation of initialize is by O(n), when n = numBlocks.                     *
*   Must supply memory block at size: blockSize * numBlocks + MP_OVERHEAD !! The overhead is for manage the pool.       *
*   Example: if blockSize = 4, numBlocks = 5 and defined that MP_OVERHEAD 8, the size of allocated mem must be 28      */
MPool* MPCreate(size_t _blockSize, size_t _numBlocks, void* _mem);

void* MPAlloc(MPool*);

/*  Free allocation. Be ware not to free the same block pointer twice!!                                                */
void MPFree(MPool*, void* _blockPtr);

/*  Calculate the unUsed blocks of memory. Operates in O(n) when n = the unused blocks                                 */
size_t MPUnused(MPool*);


#endif /* __MPOOL_H__  */
